// pages/main/main.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[

    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    const db = wx.cloud.database()
    db.collection('class').get({
      success: (res) => {
        let classes =res.data;
        //console.log(classes)
        //console.log(classes.length)
        for (let i = classes.length-1, n = 0; i >= 0; i--, n++) {  //遍历数据库对象集合
          let person = "list["+n+"].person"
          let class_name = "list["+n+"].class"
          let type = "list["+n+"].type"
          let teacher = "list["+n+"].teacher"
          let time = "list["+n+"].time"
          let release_time = "list["+n+"].release_time"
          this.setData({
            [person]: classes[i].person_name,
            [class_name]: classes[i].class_name,
            [type]: classes[i].type,
            [teacher]: classes[i].teacher,
            [time]: classes[i].week + " " + classes[i].time,
            [release_time]: "2020/06/09"
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */

  //下拉刷新
  onPullDownRefresh: function()
  {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    
    //模拟加载
    setTimeout(function()
    {
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    },1500);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  choose_course:function(){
    wx.navigateTo({
      url: '../main/choose_course/choose_course',
    })
  },
  release_course:function(){
    wx.navigateTo({
      url: '../main/release_course/release_course',
    })
  },
  main:function(){
    wx.navigateTo({
      url: '../main/main',
    })
  },
  mine:function(){
    wx.navigateTo({
      url: '../main/mine/mine',
    })
  },
  set:function(){
    wx.navigateTo({
      url: '../main/mine/set/set',
    })
  },
  my_release:function(){
    wx.navigateTo({
      url: '../main/mine/my_release/my_release',
    })
  },
  me:function(){
    wx.navigateTo({
      url: '../main/mine/me/me',
    })
  },
  rule:function(){
    wx.navigateTo({
      url: '../main/mine/rule/rule',
    })
  }
})